package com.binhai.login;

import com.alibaba.fastjson.JSON;
import com.binhai.db.SpringDB;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class LoginDao {
    @Autowired
    private SpringDB springDB;
    public String login(String username, String password) {
        JdbcTemplate jdbcTemplate = springDB.getJdbcTemplate();
        String sql = "select * from t_user where name = '" + username + "' and pass = '" + password + "' and state=0";
        //使用模版查询，返回list列表
        List list = jdbcTemplate.queryForList(sql);
        Map map = new HashMap();
        if (list.size()>0){
            map.put("result", "success");
        }else{
            map.put("result", "error");
        }
        //map转成JSON字符串
        String s = JSON.toJSONString(map);
        return s;
    }
}
